const Router = require('koa-router');
const tool = require("../../tools/tool");
const router = new Router();
const {db, Op, QueryTypes} = require("../../models/db");
const tools = require("../../tools/tool");
// 收款的业务票据及收款票据,电脑 交款核对页面
router.post('/bill/getSkBills', async ctx => {
    let body = ctx.request.body
    let tid = ctx.user.tenantId
    let billDate = body.billDate
    let uid = body.uid
    let sksql = `
            SELECT a.billDate,a.id,a.transType,a.transTypeName,a.amount,a.billNo, 
           case when a.billState='draft' then N'草稿' when a.billState='accounted' then N'已审核' end as billState 
           from invoice a where 
           a.tenantId=${tid} and a.billType='RECEIPT' and a.cby=${uid} and a.doId=${uid} and a.billState='accounted'  and a.billDate='${billDate}'
    `
    let skBills = await db.query(sksql, {type: QueryTypes.SELECT})
    let bizsql = `
    SELECT a.billDate,a.id,a.transType,a.transTypeName,a.amount,a.billNo,
           case when a.billState='draft' then N'草稿' when a.billState='accounted' then N'已审核' end as billState 
    from 
        (
        SELECT b.billId from invoice a inner join invoice_receipt b on a.id=b.iid and 
                   a.tenantId=${tid} and a.billType='RECEIPT' and a.cby=${uid} and a.doId=${uid} and a.billState='accounted' and a.billDate='${billDate}'  
        ) b inner join invoice a on b.billId=a.id
    `
    let bizBills = await db.query(bizsql, {type: QueryTypes.SELECT})
    return ctx.suc('', {
        skList: skBills,
        bizList: bizBills
    })
})










module.exports = router;